package cn.kgc.kgde.bookstore.config;

import cn.kgc.kgde.bookstore.controller.CheckUserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xiaodai
 * @create 2022-06-01 21:24
 */
@Configuration
public class BookStoreConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping( "/**" )
                .allowedOriginPatterns( "*" )
                .allowCredentials( true )
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .maxAge( 360000 )
                .allowedHeaders("*");;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CheckUserLoginInterceptor())
                .addPathPatterns( "/**" )
                .excludePathPatterns("/**");
    }
}
